﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Xml;

namespace GraphDrawing
{
    class readgraphml
    {
        
        public readgraphml(string lokacja, Canvas pole)
        {
            Counter(lokacja, pole);
            Reader(lokacja);
            
        }
        public List<Vertex> wierzcholki = new List<Vertex>();
        public List<Edge> krawedzie = new List<Edge>();
        
        Random rnd = new Random();
        private void Reader(string location)
        {
            XmlTextReader r = new XmlTextReader(location);

            
            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (r.Name == "edge")
                    {
                        string zrodlo = r.GetAttribute("source");
                        int zrodlo_nr = Convert.ToInt32(zrodlo.TrimStart('n'));
                        zrodlo = r.GetAttribute("target");
                        int cel  = Convert.ToInt32(zrodlo.TrimStart('n'));
                        //Edge krawedz =new Edge(wierzcholki[zrodlo_nr].possition,wierzcholki[cel].possition);
                        Edge krawedz = new Edge(wierzcholki, zrodlo_nr, cel);

                        krawedzie.Add(krawedz);
                    }
                }
            }
            
        }
        private void Counter(string location, Canvas obraz)
        {
            
            XmlTextReader r = new XmlTextReader(location);
           
            
            while (r.Read())
            {
                if (r.NodeType == XmlNodeType.Element)
                {
                    if (r.Name == "node")
                    {
                        Point x = new Point();
                        x.X = rnd.Next(10,(int)(obraz.ActualWidth - 50));
                        x.Y = rnd.Next(10, (int)(obraz.ActualHeight - 50));
                        wierzcholki.Add(new Vertex(10,10,x));
                        
                        
                    }
                }
            }
            
        }
    }
}
